package hu.debrecen.adastra.card.web;

import hu.debrecen.adastra.card.repository.domain.Account;
import hu.debrecen.adastra.card.service.AbstractGame;
import hu.debrecen.adastra.card.service.CardGameFactory;
import hu.debrecen.adastra.card.service.GameStoreService;
import hu.debrecen.adastra.card.service.SocialUserService;
import hu.debrecen.adastra.card.service.impl.ZsirozasCardGame;
import hu.debrecen.adastra.card.web.resolver.AutowiredHandlerAnnotationArgumentResolver.AutowiredHandler;

import javax.inject.Inject;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.google.common.base.Preconditions;

@Controller
public class ZsirGameController extends AbstractController {

	private final GameStoreService gameStoreService;

	@Inject
	public ZsirGameController(final SocialUserService socialUserService, final GameStoreService gameService, final CardGameFactory cardGameFactory) {
		super(socialUserService);
		this.gameStoreService = gameService;
	}

	@RequestMapping(value = "/game/{gameId}/pass", method = RequestMethod.POST)
	@ResponseBody
	public void pass(@AutowiredHandler final Account account, @PathVariable final String gameId) {
		AbstractGame<?> game = this.gameStoreService.getGame(gameId);

		Preconditions.checkState(game instanceof ZsirozasCardGame, "Game should be instance of Zsírozás.");

		((ZsirozasCardGame) game).pass(account);
	}
}
